﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Yawf.Web.Managers.Entities {
	public class ParameterData {
		// Origins
		public const String REQUEST_ORIGIN = "request";
		public const String SPRING_ORIGIN = "spring";
		public const String VALUE_ORIGIN = "value";
		public const String DATA_FETCHER_ORIGIN = "data-fetcher";

		// Fields
		private String name;
		private String type;
		private String origin = REQUEST_ORIGIN;
		private String valueStr;

		// Properties
		public String Name { get { return name; } set { name = value; } }
		public String Type { get { return type; } set { type = value; } }
		public String Origin { get { return origin; } set { origin = value; } }
		public String Value { get { return valueStr; } set { valueStr = value; } }

		/// <summary>
		/// Constructor with XmlElement, thois will read a parameter xml 
		/// element and read attributies into properties
		/// </summary>
		/// <param name="elem">XmlElement to read data from</param>
		public ParameterData(XmlElement elem) {
			String tmpStr;

			// Read param name
			tmpStr = elem.GetAttribute("name");
			if (tmpStr != null && tmpStr.Trim() != "") {
				Name = tmpStr;
			}

			// Read param Type
			tmpStr = elem.GetAttribute("type");
			if (tmpStr != null && tmpStr.Trim() != "") {
				Type = tmpStr;
			}

			// Read param Origin
			tmpStr = elem.GetAttribute("origin");
			if (tmpStr != null && tmpStr.Trim() != "") {
				Origin = tmpStr;
			}

			// Read param Origin
			tmpStr = elem.InnerText;
			if (tmpStr != null && tmpStr.Trim() != "") {
				Value = tmpStr.Trim();
			}
		}
	}
}
